<template>
<div>
  <div class="header">
    <div style="width: 300px">
      <img src="@/assets/logo.png" alt="" class="logoImg">
      <span class="header-span">图书管理系统</span>
    </div>
    <div style="flex: 1; text-align: right; padding-right: 20px">
      <el-dropdown size="medium">
          <span class="el-dropdown-link" style="cursor: pointer">
           {{ user.username }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
        <el-dropdown-menu slot="dropdown" style="margin-top: -5px">
          <el-dropdown-item><div style="width: 50px; text-align: center;" @click="logout">退出</div></el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
  <!-- 侧边栏导航 -->
  <div style="display: flex">
    <div class="sideMenu">
      <el-menu :default-active="$route.path"  router class="el-menu-demo">
        <el-menu-item index="/">
          <i class="el-icon-eleme"></i>
          <span>首页</span>
        </el-menu-item>


        <el-submenu index="user">
          <template slot="title">
            <i class="el-icon-user"></i>
            <span>用户管理</span>
          </template>
          <el-menu-item index="/addUser">添加用户</el-menu-item>
          <el-menu-item index="/userList">用户列表</el-menu-item>
        </el-submenu>
        <el-submenu index="admin">
          <template slot="title">
            <i class="el-icon-user-solid"></i>
            <span>管理员管理</span>
          </template>
          <el-menu-item index="/addAdmin">添加管理员</el-menu-item>
          <el-menu-item index="/adminList">管理员列表</el-menu-item>
        </el-submenu>
        <el-submenu index="category">
          <template slot="title">
            <i class="el-icon-s-operation"></i>
            <span>分类管理</span>
          </template>
          <el-menu-item index="/addCategory">添加分类</el-menu-item>
          <el-menu-item index="/categoryList">分类列表</el-menu-item>
        </el-submenu>

        <el-submenu index="book">
          <template slot="title">
            <i class="el-icon-notebook-1"></i>
            <span>图书管理</span>
          </template>
          <el-menu-item index="/addBook">添加图书</el-menu-item>
          <el-menu-item index="/bookList">图书列表</el-menu-item>
        </el-submenu>

        <el-submenu index="borrow">
          <template slot="title">
            <i class="el-icon-collection"></i>
            <span>借阅管理</span>
          </template>
          <el-menu-item index="/addBorrow">添加借阅</el-menu-item>
          <el-menu-item index="/borrowList">借阅列表</el-menu-item>
        </el-submenu>

        <el-submenu index="retur">
          <template slot="title">
            <i class="el-icon-collection"></i>
            <span>还书管理</span>
          </template>
          <el-menu-item index="/returList">还书列表</el-menu-item>
        </el-submenu>

      </el-menu>
    </div>
    <div style="flex: 1; background-color: white; padding: 10px">
      <router-view/>
    </div>
  </div>
</div>
</template>

<script>
import Cookies from "js-cookie";

export default {
  name: "Layout",
  data(){
    return{
      user:Cookies.get('admin')?JSON.parse(Cookies.get('admin')):{
        username:''
      }
    }
  },
  created() {
    console.log(this.user)
  },
  methods:{
    logout(){
      this.$router.push('/login')
      Cookies.remove('admin')
    }
  }
}
</script>

<style scoped>
.header{
  height: 60px;
  line-height: 60px;
  background-color: white;
  margin-bottom: 2px;
  display: flex;
}
.logoImg{
  width: 40px;
  height: 40px;
  margin-top: 10px;
  margin-left: 10px;
}
.header-span{
  font-size: 24px;
  margin-left: 10px;
}
.sideMenu{
  width: 200px;
  min-height: calc(100vh - 62px);
  overflow: hidden; margin-right: 2px;
  background-color: white
}
</style>